package web.interceptor;

import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;

public class CoreInterceptor  implements HandlerInterceptor {
    @Override
    public boolean preHandle(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Object handler) throws Exception {
        HttpSession session  = request.getSession();
        Long id = (Long) session.getAttribute("UID");
        if(id == null || id < 1){
            //如果没登录,则重定向到登录页
            response.sendRedirect("/user/login");
            return false;
        }
        return true;
    }
}
